#region (c) 2009 Abdullin.com and Contributors

// Copyright (c) 2009 Abdullin.com and Contributors
// Site: http://abdullin.com/ncouch
// This code is released under the terms of the new BSD licence

#endregion

using System;
using System.IO;
using System.Net;

namespace NCouch.Rest
{
	public sealed class RestResponse : IRestResponse
	{
		public int StatusCode { get; private set; }
		public long ContentLength { get; private set; }
		public string StatusDescription { get; private set; }
		readonly HttpWebResponse _response;

		public RestResponse(HttpWebResponse response)
		{
			_response = response;
			StatusCode = (int) _response.StatusCode;
			StatusDescription = _response.StatusDescription;
			ContentLength = _response.ContentLength;
		}

		void IRestResponse.RunReader(Action<Stream> read)
		{
			using (var s = _response.GetResponseStream())
			{
				read(s);
			}
		}

		string IRestResponse.ContentType
		{
			get { return _response.ContentType; }
		}


		public void Dispose()
		{
			((IDisposable) _response).Dispose();
		}
	}
}